<?php
include_once("../config/config.php");
include_once("../functions/cache.php"); 
include_once("../query/query_functions.php");

?>
<html>
	<head>
		<title>IATI Activity Viewer - <xsl:value-of select="title"/></title>
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>  	 
		<script type="text/javascript" src="/js/iati-query-builder.js"></script> 
		<script type="text/javascript" src="/js/jquery.unescape.js"></script> 
		<link media="screen" rel="stylesheet" href="activity/activity.css" />
		<link media="screen" rel="stylesheet" href="/css/iati-toolkit.css" />
		<style><!--
			div.launch-explorer {
				float:right;
				width:280px;
				height:62px;
				background:url(launchbg.jpg) no-repeat top left;
				text-align:center;
				color:#fff;
				font-size:12px;
				
			}
			div.launch-explorer span.action a{
				font-weight:bold;
				font-size:14px;
				color:#fff;
				display:block;
			}
			.count_of_text {
				display:none;
			}
			
			.count_limit_text {
				color:#0588cb;
				display:block;
			}
			
			.count_limit_text_h {
				display:block;
			}
		
			div.facet{
				width:445px;
				float:left;
				margin:0px 0px 15px 15px;
				}
			div.facet h4
				{
				color:#0588cb;
				font-size:18px;
				border-bottom: 1px solid #b8ad98;
				padding:0px 0px 5px 0px;
				margin:0px 0px 8px 0px;
				font-weight:normal
				}
			div.facet select.facet{
				width:440px;
				font-size:11px;
				}
			div.scroll {
				overflow: auto;
				height: 268px;
			}
	//--></style>

	</head>
	<body style="width:960px;margin:0 auto;">
	 
	 
		<div id="header">
			<div id="logo"></div>
		</div>
		<form id="query-builder">
			
		<h1>Choose the data you want to explore</h1>	
		
		<!--[if gt IE 6]>
		<div class="ie-only">
			Note: The IATI Explorer is a prototype that has been tested with Firefox and Chrome browsers. There are reports of some versions of Internet Explorer having difficulty accessing the IATI Explorer. If you receive an error message when using Internet Explorer, please try an alternative web browser.
		</div><![endif]-->


<div class="description">
	<div class="action url launch-explorer count_limit_grey">
		<span class="action url" id=""><a href="#" class="target" target="_parent"><?php echo $_GET['query'] ? "Update" : "Launch"; ?> Explorer</a></span>
		<span class="config">/explorer/?query=QUERY&desc=HUMAN</span>
		<div class="count-details">To explore up to <select name="howmany" class="howmany">
			<?php for($i=100;$i<1001;$i=$i+100) { 
				echo "<option value='$i'";
					if(($_GET['howmany'] ? $_GET['howmany'] : 500) == $i) { echo " SELECTED"; }
				echo ">$i</option>";
			}?>
			</select> 
			of <span class="query_count"></span> activities.</div>
	</div>	
	<!--
	The IATI Explorer allows you to explore small sets of Aid Activities in depth. It loads your chosen set of activities into your web browser and provides faceted browsing tools to let you quickly dig-down into the data. Click more-details on any activity to get a full profile of it.
	-->
	<span >Note: The IATI Explorer is a prototype that has been tested with Firefox and Chrome browsers. There are reports of some versions of Internet Explorer having difficulty accessing the IATI Explorer. If you receive an error message when using Internet Explorer, please try an alternative web browser.</span>	 		
</div>

<div class="description count_limit">
	<div class="warning_icon"></div>
	<div class="ok_icon"></div>
	<div class="warning_text">
		<span class="count_limit_text_h"><h3>Warning</h3></span>
		Your current query could fetch up to <b><span class="query_count"></span></b> activities. 
		<span class="count_limit_text"><b>The IATI Explorer works best with fewer than <span class="count_limit_number">400</span> 
			activities and will not display more than 1000 at a time. Please choose from the filter options below to narrow your selection.</b>
		</span> 
		<span class="count_ok_text">The smaller the number of activities to fetch, the more responsive the IATI explorer will be.</span>
	</div>
	<div class="clearer"></div>	
</div>


<div class="description">
	<b>Current query:</b> <span class="human_query"><?php echo ($_GET['query'] ? $_GET['desc'] : "Any project"); ?></span>
</div>

<?php if(!$_GET['query']) { ?>
<div class="description" >
	<h3 class="desc_title">Pick from the options below, and click the 'Launch Explorer' button to view these activities.</h3>

		<input name="query" id="query" type="hidden" size="50" value="//iati-activities"/>
		
		<div class="facet"><h4>Recipient Country</h4>
			<?php echo generateSelect("recipient-country/@code",1,"Country"); ?>
		</div>
		
		<div class="facet"><h4>Sector Targeted</h4>
			<?php echo generateSelect("sector/@code",1,null,"sector"); ?>
		</div>
		
		<div class="facet"><h4>Reporting Organisation</h4>
			<?php echo generateSelect("reporting-org/@ref",1,null,"reporting-org"); ?>
		</div>
		
		<div class="facet"><h4>Funding Organisation</h4>
			<?php echo generateSelect("participating-org/@ref",1,null,"participating-org[@role='Funding']"); ?>
		</div>		
	<!--
		<div class="facet"><h4>Recipient Country</h4>
			<?php echo generateSelect("recipient-country/@code",1,"Country"); ?>
		</div>
		
		<div class="facet"><h4>Regional Projects</h4>
			<?php echo generateSelect("recipient-region/@code",1,"Region"); ?>
		</div>
		
		<div class="facet"><h4>Reporting Organisation</h4>
			<?php echo generateSelect("reporting-org/@ref",1,null,"reporting-org"); ?>
		</div>
		
		<div class="facet"><h4>Funding Organisation</h4>
			<?php echo generateSelect("participating-org/@ref",1,null,"participating-org[@role='Funding']"); ?>
		</div>
		
		<div class="facet"><h4>Sector Targeted</h4>
			<?php echo generateSelect("sector/@code",1,null,"sector"); ?>
		</div>
		
		<div class="facet"><h4>Activity Status</h4>
			<?php echo generateSelect("activity-status/@code",1,"ActivityStatus"); ?>
		</div>
		
		<div class="facet"><h4>Default flow type</h4>
			<?php echo generateSelect("default-flow-type/@code",1,"FlowType"); ?>
		</div>
		
		<div class="facet"><h4>Collaboration Type</h4>
			<?php echo generateSelect("collaboration-type/@code",1,"CollaborationType"); ?>
		</div>
		
		<div class="facet"><h4>Default Aid Type</h4>
			<?php echo generateSelect("default-aid-type/@code",1,"AidType"); ?>
		</div>
		
		<div class="facet"><h4>Default finance type</h4>
			<?php echo generateSelect("default-finance-type/@code",1,"FinanceType"); ?>
		</div>	
-->
		<input type="reset" value="Reset query" class="reset-button">
		
</div>
<?php }  else {?>
	<div class="description">
		<p>
			<a href="query.php">Create new query.</a>
		</p>
		<br/>
		<p><small>(Sorry we can't let you edit your existing query just yet. We're working on it...)</small></p>
	</div>
<?php } ?>
</form>
</body>
</html>